package com.junyidao.game.core;

import com.junyidao.game.pojo.SysUser;
import com.junyidao.game.vo.SysPrivVo;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 登录信息
 * Created by HP on 2016/8/13.
 */
public class LoginInfo {

    public static final String SESSION_USER = "user";

    public static final String USER_PRIV_LIST = "user_priv_lsit";

    public static final String SESSION_MENU = "menuList";

    public static SysUser getUser() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        SysUser user = (SysUser) request.getSession().getAttribute(SESSION_USER);
        return user;
    }

    public static void setUser(SysUser user) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        request.getSession().setAttribute(SESSION_USER, user);
    }

    public static void removeUser() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        request.getSession().removeAttribute(SESSION_USER);
    }

    public static void setSysPriv(List<SysPrivVo> privVoList) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        request.getSession().setAttribute(USER_PRIV_LIST, privVoList);
    }

    public static List<SysPrivVo> getSysPriv() {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        List<SysPrivVo> privList = (List<SysPrivVo>) request.getSession().getAttribute(USER_PRIV_LIST);
        return privList;
    }

    public static void setMenu(List<SysPrivVo> menuList) {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        request.getSession().setAttribute(SESSION_MENU, menuList);
    }

}
